<template>
	<view class="add">
		<u-navbar
			title="新建缴费类型"
			:border-bottom="false"  
		>
			<view class="navbar__right" slot="right">
				<view class="navbar__right__icon">
					<u-icon name="more-dot-fill" @click="bill__more"></u-icon>
				</view>
				<view class="navbar__right__icon">
					<u-icon name="setting"></u-icon>
				</view>
			</view>
		</u-navbar>
		<view class="add__block">
			<view class="add__block__param">
				<view class="add__block__param__select">
					<v-require-text class="add__block__param__select__name">
						园区
					</v-require-text>
					<view class="add__block__param__select__value">
						<view v-if="parkId!=''" class="add__block__param__select__value--filled" @click="parkSelect=true">{{parkName}}</view>
						<view v-else @click="parkSelect=true">请选择</view>
						<u-icon name="arrow-right"></u-icon>
					</view>

				</view>
				<u-select 	v-model="parkSelect"
							:list="parkList" 
							@confirm="parkConfirm"
							value-name="id"
							label-name="parkName"></u-select>
							
			</view>
		</view>
		
		<view class="add__block">
					<view class="add__block__param">
						<view class="add__block__param__input">
							<v-require-text class="add__block__param__input__name">
								类型
							</v-require-text>
							<view class="add__block__param__input__value">
								<u-field
									v-model="name"
									input-align="right"
									placeholder="输入类型名"
									:border-bottom="false"
								>
								</u-field>
							</view>
						</view>
					</view>
				</view>
				<view class="add__bottom-box">
					<view class="add__bottom-box__cancel" @click="cancelModel=true">取消</view>
					<view class="add__bottom-box__submit" @click="clickSubmit">提交</view>
				</view>
				<u-modal v-model="cancelModel"
					:show-title="false"
					content="确认取消"
					:show-cancel-button="true"
					confirm-color="#177fff"
					@confirm="goback">
				</u-modal>
				<u-modal v-model="submitModel" 
					:show-title="false"
					content="确认提交"
					:show-cancel-button="true"
					confirm-color="#177fff"
					@confirm="submit">
				</u-modal>

	</view>
</template>

<script>
	import testData from './testData.js'
	import requireText from '../../../../component/requireText.vue'
	export default {
		components:{
			'v-require-text':requireText
		},
		data() {
			return {
				parkId:"",
				parkName:"",
				name:"",
				parkSelect:false,
				cancelModel:false,
				submitModel:false,
				parkList:[],
			}
		},
		mounted(){
			this.getParkList()
			// this.enterpriseList=testData.enterPriseList;
			// this.billTypeList=testData.billTypeList;
		},
		methods: {
			parkConfirm(park){
				console.log(park);
				this.parkId=park[0].value;
				this.parkName=park[0].label
			},
			clickSubmit(){
				if(this.parkId==''){
					uni.showToast({
						title:"请选择园区",
						icon:"none",
						duration:2000
					})
					return
				}
				if(this.name==''){
					uni.showToast({
						title:"请输入类型名",
						icon:"none",
						duration:2000
					})
					return
				}
				this.submitModel=true	
			},
			submit(){
				console.log("this.parkid",this.parkId)
				let addData={
					parkId:this.parkId,
					name:this.name
				}
				uni.showLoading()
				console.log("开始请求添加")
				this.$Axios({
					url:this.$store.state.baseURL+"/bill/bill-type/add",
					method:"post",
					data:addData
				}).then(response=>{
					console.log("请求结果",response)
					uni.hideLoading()
					if(response.data.state=="success"){
						uni.showToast({
							title:"新建缴费成功",
							icon:"none",
							duration:2000,
							success() {
								setTimeout(function(){
									uni.navigateTo({
										url:"/pages/core/service/bill/billType"
									});
								},1000)
							}
						})
					}else{
						uni.showToast({
							title:response.data.msg,
							icon:"none",
							duration:2000
						})
					}
				})
				// 提交请求

			
			},
			goback(){
				console.log("back")
				uni.navigateBack({
					animationDuration:1000,
					animationType:"pop-out"
				})
			},
			getParkList(){
				this.$Axios({
					method:"get",
					url:this.$store.state.baseURL+"/park/all",
				}).then((response)=>{
					let responseData=response.data
					console.log(responseData)
					this.parkList=response.data.msg;
				});
			}
		}
	}
</script>

<style lang="less">
.navbar{
	&__right{
		display: flex;
		flex-direction: row;
		margin-right: @uni-spacing-col-base;
		margin-left: auto;

		&__icon{
			font-size: @uni-font-size-x-lg;
			margin-left: @uni-spacing-col-base;
			margin-right: @uni-spacing-col-base;
		}
	}
}
.add{
	display: flex;
	flex-direction: column;
	background-color: @uni-bg-color-grey;
	padding-bottom: @uni-spacing-row-lg;
	height: calc(100vh);
	&__block{
		display: flex;
		flex-direction: column;
		margin-top: @uni-spacing-row-sm;
		padding-left: @uni-spacing-col-lg;
		padding-right: @uni-spacing-col-lg;
		// background-color: #fff;
		&__param{
			font-display: flex;
			flex-direction: column;

			&__select{
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				padding-top: @uni-spacing-row-lg;
				padding-bottom: @uni-spacing-row-lg;
				&__title{
					
				}
				&__textarea{
					margin-left: 0;
					margin-right: auto;
				}
				&__value{
					display: flex;
					flex-direction: row;
					color: @font-color-grey;
					&__filled{
						color: @font-color-black;
					}
				}

			}
			&__input{
				display: flex;
				flex-direction: row;
				// justify-content: space-between;
				align-items: center;
				// padding-top: @uni-spacing-row-lg;
				// padding-bottom: @uni-spacing-row-lg;
				&__title{
					
				}
				&__value{
					display: flex;
					flex-direction: row;
					flex: 1;
					color: @font-color-grey;
					&__filled{
						color: @font-color-black;
					}
				}
			
			}
		}
	}

	&__bottom-box{
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		position: fixed;
		padding: @uni-spacing-row-lg @uni-spacing-col-lg;
		bottom: 0;
		width: calc(100vw);
		background-color: #fff;
		
		&__cancel{
			margin-right: @uni-spacing-col-lg;
			padding-top: @uni-spacing-row-base;
			padding-bottom: @uni-spacing-row-base;
			text-align: center;
			flex: 0.5;
			border-radius: @uni-border-radius-base;
			border: 1px solid @font-color-blue;
			font-size: @uni-font-size-lg;
			color: @font-color-blue;
		}
		&__submit{
			padding-top: @uni-spacing-row-base;
			padding-bottom: @uni-spacing-row-base;
			text-align: center;
			flex: 1;
			border-radius: @uni-border-radius-base;
			border: 1px solid @font-color-blue;
			background-color: @uni-bg-color-blue;
			font-size: @uni-font-size-lg;
			color: #fff;
		}
	}
}
</style>
